package com.sptpc.paintdemo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import java.util.ArrayList;

public class TestCanvasView extends View {
        Paint paint;
        private ArrayList<PointF> graphics = new ArrayList<>();
        PointF pointF;

    public TestCanvasView(Context context) {
        super(context);
        paint = new Paint();
        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.FILL);
        paint.setStrokeJoin(Paint.Join.ROUND); //设置连接              BEVEL 直线 ，ROUND 圆形 ，MITER 锐角
        paint.setStrokeCap(Paint.Cap.ROUND); //设置笔帽类型
        paint.setStrokeWidth(8); //设置宽度

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        graphics.add(new PointF(event.getX(),event.getY()));
        invalidate();
        return true;

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(10,10,280,150,paint);
        canvas.drawLine(100,100,300,300,paint);
        canvas.drawCircle(300,300,20,paint);
        for (PointF point : graphics)
        {
            canvas.drawPoint(point.x,point.y,paint);
        }
    }
}
